// Copyright (c) 2010 Thomas Stuefe
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#pragma once

namespace zencat {
namespace sqlite {


	/// <summary>
	/// Describes sqlite error codes. For a detailed description about what the 
	/// </summary>
	public enum class ErrorCode {

		EC_UNKNOWN = -1,

		// see http://www.sqlite.org/c3ref/c_abort.html

		EC_SQLITE_OK           = 0, // Successful result
		EC_SQLITE_ERROR        = 1, // SQL error or missing database
		EC_SQLITE_INTERNAL     = 2, // NOT USED. Internal logic error in EC_SQLITE
		EC_SQLITE_PERM         = 3, // Access permission denied
		EC_SQLITE_ABORT        = 4, // Callback routine requested an abort
		EC_SQLITE_BUSY         = 5, // The database file is locked
		EC_SQLITE_LOCKED       = 6, // A table in the database is locked
		EC_SQLITE_NOMEM        = 7, // A malloc() failed
		EC_SQLITE_READONLY     = 8, // Attempt to write a readonly database
		EC_SQLITE_INTERRUPT    = 9, // Operation terminated by EC_SQLITE3_interrupt()
		EC_SQLITE_IOERR       = 10, // Some kind of disk I/O error occurred
		EC_SQLITE_CORRUPT     = 11, // The database disk image is malformed
		EC_SQLITE_NOTFOUND    = 12, // NOT USED. Table or record not found
		EC_SQLITE_FULL        = 13, // Insertion failed because database is full
		EC_SQLITE_CANTOPEN    = 14, // Unable to open the database file
		EC_SQLITE_PROTOCOL    = 15, // NOT USED. Database lock protocol error
		EC_SQLITE_EMPTY       = 16, // Database is empty
		EC_SQLITE_SCHEMA      = 17, // The database schema changed
		EC_SQLITE_TOOBIG      = 18, // String or BLOB exceeds size limit
		EC_SQLITE_CONSTRAINT  = 19, // Abort due to constraint violation
		EC_SQLITE_MISMATCH    = 20, // Data type mismatch
		EC_SQLITE_MISUSE      = 21, // Library used incorrectly
		EC_SQLITE_NOLFS       = 22, // Uses OS features not supported on host
		EC_SQLITE_AUTH        = 23, // Authorization denied
		EC_SQLITE_FORMAT      = 24, // Auxiliary database format error
		EC_SQLITE_RANGE       = 25, // 2nd parameter to EC_SQLITE3_bind out of range
		EC_SQLITE_NOTADB      = 26, // File opened that is not a database file
		EC_SQLITE_ROW         = 100, // EC_SQLITE3_step() has another row ready
		EC_SQLITE_DONE        = 101, // EC_SQLITE3_step() has finished executing

		// extended error codes, see http://www.sqlite.org/c3ref/c_busy_recovery.html
		EC_SQLITE_IOERR_READ				= (EC_SQLITE_IOERR | (1<<8)),
		EC_SQLITE_IOERR_SHORT_READ			= (EC_SQLITE_IOERR | (2<<8)),
		EC_SQLITE_IOERR_WRITE				= (EC_SQLITE_IOERR | (3<<8)),
		EC_SQLITE_IOERR_FSYNC				= (EC_SQLITE_IOERR | (4<<8)),
		EC_SQLITE_IOERR_DIR_FSYNC			= (EC_SQLITE_IOERR | (5<<8)),
		EC_SQLITE_IOERR_TRUNCATE			= (EC_SQLITE_IOERR | (6<<8)),
		EC_SQLITE_IOERR_FSTAT				= (EC_SQLITE_IOERR | (7<<8)),
		EC_SQLITE_IOERR_UNLOCK				= (EC_SQLITE_IOERR | (8<<8)),
		EC_SQLITE_IOERR_RDLOCK				= (EC_SQLITE_IOERR | (9<<8)),
		EC_SQLITE_IOERR_DELETE				= (EC_SQLITE_IOERR | (10<<8)),
		EC_SQLITE_IOERR_BLOCKED				= (EC_SQLITE_IOERR | (11<<8)),
		EC_SQLITE_IOERR_NOMEM				= (EC_SQLITE_IOERR | (12<<8)),
		EC_SQLITE_IOERR_ACCESS				= (EC_SQLITE_IOERR | (13<<8)),
		EC_SQLITE_IOERR_CHECKRESERVEDLOCK	= (EC_SQLITE_IOERR | (14<<8)),
		EC_SQLITE_IOERR_LOCK				= (EC_SQLITE_IOERR | (15<<8)),
		EC_SQLITE_IOERR_CLOSE				= (EC_SQLITE_IOERR | (16<<8)),
		EC_SQLITE_IOERR_DIR_CLOSE			= (EC_SQLITE_IOERR | (17<<8)),
		EC_SQLITE_IOERR_SHMOPEN				= (EC_SQLITE_IOERR | (18<<8)),
		EC_SQLITE_IOERR_SHMSIZE				= (EC_SQLITE_IOERR | (19<<8)),
		EC_SQLITE_IOERR_SHMLOCK				= (EC_SQLITE_IOERR | (20<<8)),
		EC_SQLITE_LOCKED_SHAREDCACHE		= (EC_SQLITE_LOCKED |  (1<<8)),
		EC_SQLITE_BUSY_RECOVERY				= (EC_SQLITE_BUSY   |  (1<<8)),
		EC_SQLITE_CANTOPEN_NOTEMPDIR		= (EC_SQLITE_CANTOPEN | (1<<8))


	}; // end: ErrorCode

	// helper, translate an sqlite numerical error code to the ErrorCode enum
	ErrorCode errorCodeFromRawCode (int raw);

} // end namespace sqlite

} // end namespace zencat